﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BarberShop.BLL;


public partial class AdImgPlaySort : System.Web.UI.Page
{
    public int Id
    {
        get
        {
            return string.IsNullOrEmpty(Request.QueryString["id"]) ? 0 : Convert.ToInt32(Request.QueryString["id"]);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetPlayList();
            GetData();
            //GetMoviePlayListData();
        }
    }

    protected void btn_search_Click(object sender, EventArgs e)
    {
        //GetMoviePlayListData();
    }

    protected void GetPlayList()
    {
        var data = AdImgPalyListBLL.GetAdPlayListInfo("");
        drp_moviePlayList.DataSource = data;
        drp_moviePlayList.DataTextField = "Name";
        drp_moviePlayList.DataValueField = "id";
        drp_moviePlayList.SelectedValue = Id.ToString();
        drp_moviePlayList.DataBind();
    }

    //getData
    protected void GetData()
    {
        var data = AdImgPalyListBLL.GetViewAdPalyList(Id);
        this.Grid_1.DataSource = data;
        this.Grid_1.DataKeyNames = new string[] { "PlayListId", "PlayListReId", "playindex" };
        this.Grid_1.DataBind();
    }

    protected void Grid_1_RowDataBound(object sender, GridViewRowEventArgs e)
    {

    }
    protected void Grid_1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int NewPlayindex = Convert.ToInt32(((TextBox)(Grid_1.Rows[e.RowIndex].Cells[0].Controls[0])).Text);
        int PlayListId = Convert.ToInt32(Grid_1.DataKeys[e.RowIndex]["PlayListId"].ToString());
        int PlayListReId = Convert.ToInt32(Grid_1.DataKeys[e.RowIndex]["PlayListReId"].ToString());
        int OldPlayindex = Convert.ToInt32(Grid_1.DataKeys[e.RowIndex]["playindex"].ToString());
        AdPlayListRelationBLL.ModifyPlayIndex(PlayListId, PlayListReId, NewPlayindex, OldPlayindex);
        this.Grid_1.EditIndex = -1;
        GetData();
    }
    protected void Grid_1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        this.Grid_1.EditIndex = e.NewEditIndex;
        GetData();
    }
    protected void Grid_1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.Grid_1.PageIndex = e.NewPageIndex;
        GetData();
    }
    protected void Grid_1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        this.Grid_1.EditIndex = -1;
        GetData();
    }
    protected void Grid_1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int PlayListReId = Convert.ToInt32(Grid_1.DataKeys[e.RowIndex]["PlayListReId"].ToString());
        int PlayListId = Convert.ToInt32(Grid_1.DataKeys[e.RowIndex]["PlayListId"].ToString());
        int OldPlayindex = Convert.ToInt32(Grid_1.DataKeys[e.RowIndex]["playindex"].ToString());
        bool r=AdPlayListRelationBLL.DelPlayList(PlayListReId);
        if (r) AdPlayListRelationBLL.UpdatePlayIndex(PlayListId, OldPlayindex);
        GetData();
    }
}
